package com.jgsu.farm.mapper.sql;

import com.jgsu.farm.entity.BiologyCategory;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

@Repository
public interface BiologyMapperSql {
    @Insert("insert into biologycategory(kingdom,phylum,class,bio_order,family,genus,species) values(#{kingdom},#{phylum},#{bio_class},#{order},#{family},#{genus},#{species})")
    @Options(useGeneratedKeys = true, keyProperty = "bioid", keyColumn = "bioID")
    int insert(BiologyCategory biologycategory);

    @Select("select bioid from biologycategory where species = #{species}")
    int select(String species);


    @Select("select * from biologycategory where kingdom = #{kingdom} and phylum = #{phylum} and class = #{bio_class} and bio_order = #{order} and family = #{family} and genus = #{genus} and species = #{species} ")
    Integer selectBio(BiologyCategory biologycategory);

    @Select("select bioid from biologycategory where kingdom = #{kingdom} and phylum = #{phylum} and class = #{bio_class} and bio_order = #{order} and family = #{family} and genus = #{genus} and species = #{species}")
    BiologyCategory selectId(BiologyCategory biologycategory);


    @Select("select bioID from biologycategory where bioID = #{bioid}")
    int selectById(Integer bioid);

    @Results(id = "biologyCategoryMap",value = {
            @Result(id = true,column = "bioid",property = "bioid"),
            @Result(column = "kingdom",property = "kingdom"),
            @Result(column = "phylum",property = "phylum"),
            @Result(column = "class",property = "bio_class"),
            @Result(column = "bio_order",property = "order"),
            @Result(column = "family",property = "family"),
            @Result(column = "genus",property = "genus"),
            @Result(column = "species",property = "species"),
    })
    @Select("select * from biologycategory where bioID = #{bioid}")
    BiologyCategory selectCategoryById(Integer bioid);

    /**
     * 根据id删除胁迫类型
     */
    @Delete("delete from biologycategory where bioID = #{bioid}")
    int deleteById(Integer bioid);
}
